<script type="text/javascript">
$(document).ready(function(){
    $.formValidator.initConfig({
        formid:"safeform",
        validatorgroup:"safeform"
    });

    $("#phoneno").formValidator({
        validatorgroup:"safeform",
        onshow:"请输您的手机号码",
        onfocus:"请输您的手机号码",
        oncorrect:"请确认您的手机号码"
    }).inputValidator({
        min:11,
        max:11,
        empty:{leftempty:false,rightempty:false,emptyerror:"您输手机号码有误"},
        onerror:"请输入正确的手机号"
    }).regexValidator({
        regexp:"^(13|15|18|14)\\d{9}$"
    });
    
    $("#ackcode").formValidator({
        validatorgroup:"safeform",
        onshow:"请输入发送到您手机上的验证码",
        onfocus:"请输入发送到您手机上的验证码",
        oncorrect:"请确认验证码信息"
    }).inputValidator({
        min:1,
        empty:{leftempty:false,rightempty:false,emptyerror:"请输入验证码"},
        onerror:"请输入验证码"
    });
    $("#btnGetCode").click(function(){get_ackcode();});
    $("#btnSafecount").click(function(){send_safecount();});
});


function send_safecount(){
    var pass=$.formValidator.pageIsValid('safeform');
    var ackcode = $("#ackcode").attr("value");
    if(pass){
        $.post(APP+'/Member/dosafecount',
        {
        "ackcode":ackcode
        },
        function(data,success){
            if(data==2){
                tlsalert("认证成功!");
                mbsimajax(APP+'/Member/mb_safecount/','mbAjaxShow');
            }else if(data==1){
                tlsalert("此号码已被他人使用");
            }else if(data==0){
                tlsalert("认证失败");
            }else if(data==3){
                tlsalert("此号码已认证过");
            }
        });
    }else{
        tlsalert('输入格式有误');
    }
}

function tlsalert(txt){
    addDialogbox("#tlsalertbox","帐户安全认证",10001,302);
    msg=txt+'<br /><br />'+
    '<div class="tc">'+
    '<span class="button">'+
    '<span class="first-child">'+
    '<button type="button" class="f12" onclick="removeDialogbox(\'#tlsalertbox\');">我知道了，返回</button>'+
    '</span>'+
    '</span>'+
    '</div>';
    $("#tlsalertbox .dialogboxContent").html(msg);
}

function chkReg(reg,str){ 
   regObj = new RegExp(reg);
   return regObj.test(str); 
 } 

function get_ackcode(){
    var phoneno = $("#phoneno").attr("value");
    var reg = "^(13|15|18)\\d{9}$"; 
    pass = chkReg(reg,phoneno);
    if(pass){
        $('#btnGetCode').attr('disabled','disabled');
        $.post(APP+'/Member/sendCode',
        {
        "phoneno":phoneno
        },
        function(data,success){
            if(data==0){
                tlsalert("验证码发送失败。");
                $('#btnGetCode').removeAttr('disabled');
            }else if(data==2){
                tlsalert("此手机号码已被其他帐户绑定。");
                $('#btnGetCode').removeAttr('disabled');
            }else if(data==1){
                tlsalert("验证码已发送到您手机。");
                $("#PackPhone").attr("style","display:none");
                $("#Packcode").removeAttr("style");
            }else if(data==3){
                tlsalert("每人每天最多操作三次，操作失败。");
            }
        });
    }else{
        tlsalert('手机号码不正确。');
    }
    
}
</script>



<div class="container regWrap">
    <div class="tabview">
      <h2 class="title fl">账户安全认证</h2></div>
   <eq name="user['state']" value="1">
      <div class="content" style="display:block;">
            <p class="inputWrap">您已通过账户安全认证。</p>
            <p class="inputWrap">
                <label for="pointcode">手机:</label>
                <input class="input" name="phoneno1" disabled="disabled" id="phoneno1" style="width:220px;" value="{$user.phone}" />
            </p>
      </div>
   <else/>
      <form id="safeform">
        <div class="content" style="display:block;">
           <p class="inputWrap">请输入您的手机号码，点击获取验证码，开始验证。（短信免费，由{$Think.config.sysconfig.webname}承担）</p>
            <p class="inputWrap">根据通信网络情况会有1-5分钟的延时，如果超时未收到验证码，请重新获取或请发邮件到{$Think.config.sysconfig.services_email}与我们联系！谢谢。</p>
            <p class="inputWrap">请勿使用他人手机。</p>
            <div id="PackPhone">
            <p class="inputWrap">
                <label for="phoneno">手机:</label>
                <input class="input" name="phoneno" id="phoneno" style="width:220px;" />
                <span id="phonenoTip"></span>
            </p>
            <p>
                <span class="button">
                    <span class="first-child">
                        <button type="button" id='btnGetCode' class="strong" >下一步 获取验证码</button>
                    </span>
                </span>
            </p>
            </div>
            <div id="Packcode" style="display:none;">
            <p class="inputWrap">
                <label  for="ackcode">请输入您短信收到的验证码:</label>
                <input class="input" name="ackcode" id="ackcode" style="width:220px;" />
            </p>
            <p>
                <span class="button">
                    <span class="first-child">
                        <button type="button" id='btnSafecount' class="strong" >确认</button>
                    </span>
                </span>
            </p>
            </div>

        </div>
        </form>
    </eq>
</div>


















